import reducer from '@/reducers/todoList'
import { ADD, REMOVE, COMPELETED } from '@/actions/todoList'

export default(ctx) => {
  const {
    addItem,
    removeItem,
    changeCompeleted
  } = reducer(ctx.todoData)

  return function(type, arg){
    switch(type){
      case ADD:
        ctx.todoData = addItem(arg)
        break;
      case REMOVE:
        ctx.todoData = removeItem(arg)
        break;
      case COMPELETED:
        ctx.todoData = changeCompeleted(arg)
        break;
      default:
        break;
    }
  }
}
